// pages/hetong/hetong.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    EventEmitter:[],
    navScrollLeft: 0,
    winWidth: 0,
    winHeight: 0, 
    currentTab:0,
    currentTab1:0,
    hidden: true,
    faqi_ht:"",
    countdown: '',
    listData: [],
    currentUrlIndex: 0,
    articles: [],
    hidden: true,
    loadingData: false,
    show:false,
  },
  loadData: function(tail, callback) {
    if(app.globalData.lishi ==undefined){
      app.globalData.lishi=0
    }
     var that = this,
      urlIndex = that.data.currentUrlIndex;
      if(urlIndex==0){
        urlIndex=1
      }
      var shul = 30*1*urlIndex*1
      console.log(shul)
      app.globalData.shul = shul
      var that = this
      wx.request({
      url: app.globalData.url_l + 'api/member/hetong_list',
      method: 'post',
      data:{
          uid:app.globalData.uid,
          state:app.globalData.state1,
          shu:app.globalData.shul,
          content:app.globalData.qshu,
          type:app.globalData.type1
      },
        method: 'post',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
          console.log(222222222)
          console.log(res)
            wx.hideNavigationBarLoading();
            wx.stopPullDownRefresh();
            if(res.data.length==0){
              wx.showToast({
                title: "没有更多数据！",
                icon: 'none',
                duration: 2000
              })
            }
            if(res.data.shi==""){
              that.setData({
                meiyougengdu: "display:block"
              })
            }
            var oldArticles =that.data.faqi_ht,
            newArticles = tail ? oldArticles.concat(res.data) : res.data;
            app.globalData.cd_id1=newArticles.length
            var shi_dj = [];
          app.globalData.po=(urlIndex + 1) >= res.data.length? 0 : urlIndex + 1
          console.log(newArticles)
          that.setData({
            
            faqi_ht:newArticles,
            currentUrlIndex: (urlIndex + 1) >= res.data.length ? 0 : urlIndex + 1,
            sj_xz:"display:none",
            sj_xz1:"display:none",
          });
          wx.hideNavigationBarLoading();
          wx.stopPullDownRefresh();
          if (callback) {
            callback();
          }
        },
      })
  // }
  },
  
  // /**
  //  * 监听用户下拉动作
  //  */
  onPullDownRefresh: function() {
    var that = this
  wx.request({
    url: app.globalData.url_l + 'api/member/hetong_list',
    method: 'post',
    data:{
        uid:app.globalData.uid,
        state:0,
        shu:0,
        content:app.globalData.qshu,
        type:app.globalData.type1
    },
    timeout:3000,
    method: 'post',
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    success: function (res) {
      console.log(11111111)
      console.log(res)
         wx.hideNavigationBarLoading();
         wx.stopPullDownRefresh();
        // app.globalData.huancun = res.data.list
        that.setData({
          tui_j:res.data.data
        })
        //that.setCountDown();
     
    },
  })
  
  wx.showToast({
    title: "数据加载中...",
    icon: 'loading',
    duration: 2000
  })
  
  },
  onReachBottom:function(){
    console.log("触底了");
    console.info('onReachBottom');
  var hidden = this.data.hidden,
    loadingData = this.data.loadingData,
    that = this;
  if (hidden) {
    this.setData({
      hidden: false
    });
    //console.info(this.data.hidden);
  }
  if (loadingData) {
    return;
  }
  this.setData({
    loadingData: true
  });
  // 加载数据,模拟耗时操作
  wx.showToast({
    title: "数据加载中...",
    icon: 'loading',
    duration: 2000
  });
  
  setTimeout(function() {
    that.loadData(true, () => {
      that.setData({
        hidden: true,
        loadingData: false
      });
    });
     console.info('上拉数据加载完成.');
    }, 1000);
  },
  qs_i:function(e){
    console.log(e.detail.value)
    app.globalData.qshu = e.detail.value
  },
  sou:function(){
    var that = this;
    wx.request({
      url: app.globalData.url_l + 'api/member/hetong_list',
      method: 'post',
      data:{
          uid:app.globalData.uid,
          state:app.globalData.state1,
          shu:0,
          content:app.globalData.qshu,
          type:app.globalData.type1
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res)
        that.setData({
          faqi_ht:res.data
        })
        
      }
    })
  },
  het:function(event){
    var that = this;
    var he_id = event.currentTarget.dataset.id; 
    var type = event.currentTarget.dataset.ty; 
    app.globalData.type1 = type
    
    app.globalData.type11 = type
    app.globalData.qs_ht = he_id
    console.log(he_id)
    wx.navigateTo({
      url: '../ck_qs/ck_qs?he_id='+he_id+"&type="+app.globalData.type1,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var sq_id = options.sq_id;
    console.log(sq_id)
    
 
    if(sq_id==0){
      app.globalData.state1= ''
      app.globalData.type1 = ""
      that.setData({
        currentTab:0
      })
    }else if(sq_id==1){
      app.globalData.state1 = 2
      app.globalData.type1 = 0
      that.setData({
        currentTab:1
      })
    }else if(sq_id==2){
      app.globalData.state1 = 2
      app.globalData.type1 = 1
      that.setData({
        currentTab:2
      })
    }
      wx.request({
        url: app.globalData.url_l + 'api/member/hetong_list',
        method: 'post',
        data:{
            uid:app.globalData.uid,
            shu:0,
            state:app.globalData.state1,
            type:app.globalData.type1
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
          console.log(res)
          that.setData({
            faqi_ht:res.data,
          })
          
        }
      })
    
    
   
    wx.getSystemInfo({
      success: (res) => {
          this.setData({
              pixelRatio: res.pixelRatio,
              windowHeight: res.windowHeight,
              windowWidth: res.windowWidth
          })
      },
  }) 
  },
  switchNav(event){
    var that = this;
    wx.showLoading({
      title: '加载中',
      mask:false
    })
    var cur = event.currentTarget.dataset.current; 
    if(cur==0){
        app.globalData.state1= ''
        app.globalData.type1 = ""
      }else if(cur==1){
        app.globalData.state1 = 2
        app.globalData.type1 = 0
      }else if(cur==2){
        app.globalData.state1 = 2
        app.globalData.type1 = 1
      }else if(cur==3){
        app.globalData.state1 = 3
        app.globalData.type1 = ""
      }else if(cur==4){
        app.globalData.state1 = 4
        app.globalData.type1 = ""
      }
      else if(cur==5){
        app.globalData.state1 = 5
        app.globalData.type1 = ""
      }
      that.setData({
        currentTab:cur
      })
      

      wx.request({
        url: app.globalData.url_l + 'api/member/hetong_list',
        method: 'post',
        data:{
            uid:app.globalData.uid,
            state:app.globalData.state1,
            shu:0,
            content:app.globalData.qshu,
            type:app.globalData.type1
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
          console.log(res)
          
          that.setData({
            faqi_ht:res.data
          })
          setTimeout(function () {
            wx.hideLoading()
          }, 1000)
        }
      })
  
    
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    app.globalData.qshu = ''
    app.globalData.state1 = ''
    app.globalData.type1 = ""
    if(app.globalData.sc==2){
      wx.showModal({
        title: '温馨提示',
        content:app.globalData.sc_ts,
        success (res) {
          if (res.confirm) {
            wx.switchTab({
              url: '../index/index',
            })
          } else if (res.cancel) {
            wx.switchTab({
              url: '../index/index',
            })
          }
        }
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})